function setCookie(key, val, day, path = '/') {
    if (day) {
        var date = new Date();
        date.setDate(date.getDate() + day);
        document.cookie = key + '=' + val + ';expires=' + date.toUTCString() + ';path=' + path;
    } else {
        document.cookie = key + '=' + val + ';path=' + path;
    }
}

function getCookie(key) {
    var cookie = document.cookie;
    if (cookie) { //有cookie时
        var list = cookie.split("; ");
        // console.log(list); //  ["user=a123123", "pwd=123123", "phone=17386141517", "email=1272071495@qq.com"]
        for (var i = 0; i < list.length; i++) {
            var item = list[i]; // "user=a123123", "pwd=123123",
            var name = item.split("=")[0];
            var val = item.split("=")[1];
            if (name === key) {
                return decodeURIComponent(val);
            }
        }
    }
    return "";
}

function delCookie(key) {
    setCookie(key, "", -1);
}